Skip to content

CAMEL-23479: Fix camel.main.virtualThreadsEnabled not working#23307

Merged
davsclaus merged 2 commits into
apache:mainfrom
davsclaus:fix/camel-23479-virtual-threads-early-config
May 19, 2026
Merged

CAMEL-23479: Fix camel.main.virtualThreadsEnabled not working#23307
davsclaus merged 2 commits into
apache:mainfrom
davsclaus:fix/camel-23479-virtual-threads-early-config

Conversation

@davsclaus
Copy link
Copy Markdown
Contributor

Summary

Fixes two distinct bugs where camel.main.virtualThreadsEnabled=true failed to enable virtual threads:

  • Race condition (properties file path): autoconfigure() set the system property camel.threads.virtual.enabled after camelContext.build() had already triggered ThreadType.current(), which uses a permanent double-checked-locking cache. Once cached as PLATFORM, the value was never re-evaluated.
  • Programmatic path always broken: main.configure().withVirtualThreadsEnabled(true) set mainConfigurationProperties.virtualThreadsEnabled=true but autoConfigurationSingleOption only reads external sources — the system property was never set, so ThreadType.current() always returned PLATFORM.

Fix:

  1. Add configureVirtualThreadsEarly() to BaseMainSupport, called before camelContext.build(). It checks all config sources in priority order: programmatic → initialPropertiesPropertiesComponent (application.properties) → ENV vars → JVM system props.
  2. Add ThreadType.enable() in camel-util to directly set the cached value to VIRTUAL, overriding any value that may have been cached earlier in the bootstrap sequence.
  3. New test class MainVirtualThreadsTest covering both previously-broken paths.

Test plan

  • MainVirtualThreadsTest.testProgrammaticVirtualThreadsEnabled — verifies main.configure().withVirtualThreadsEnabled(true) correctly sets ThreadType.VIRTUAL
  • MainVirtualThreadsTest.testInitialPropertyVirtualThreadsEnabled — verifies main.addInitialProperty("camel.main.virtualThreadsEnabled", "true") correctly sets ThreadType.VIRTUAL
  • Both tests pass in isolation and as part of the full camel-main test suite

Relates to: https://issues.apache.org/jira/browse/CAMEL-23479

Claude Code on behalf of Claus Ibsen

🤖 Generated with Claude Code

Two bugs fixed:

1. Race condition: autoconfigure() set the system property after
   camelContext.build() could already have triggered ThreadType.current()
   and permanently cached PLATFORM via double-checked locking.

2. Programmatic case broken: main.configure().withVirtualThreadsEnabled(true)
   set mainConfigurationProperties but never set the system property,
   so ThreadType.current() always returned PLATFORM.

Fix: add configureVirtualThreadsEarly() called before camelContext.build()
that checks all config sources (programmatic, initialProperties, PropertiesComponent,
ENV, JVM system props) and sets the system property early. Also adds
ThreadType.enable() to directly set the cached value, overriding any value
already cached before this point.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
// configure custom main listeners
configureMainListener(camelContext);
// configure virtual threads early before build() to avoid ThreadType DCL race
configureVirtualThreadsEarly(camelContext);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Yes, the autoConfigurationSingleOption call for virtualThreadsEnabled is now redundant — configureVirtualThreadsEarly() covers all the same configuration sources and runs at the right moment (before camelContext.build()). Removed it in the follow-up commit.

Claude Code on behalf of Claus Ibsen

@github-actions github-actions Bot added the core label May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

…SingleOption

configureVirtualThreadsEarly() now covers all configuration sources and
runs before camelContext.build(), making the later autoConfigurationSingleOption
call for virtualThreadsEnabled redundant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@davsclaus davsclaus requested a review from Croway May 18, 2026 19:30
@github-actions
Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • core/camel-main
  • core/camel-util

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.

Build reactor — dependencies compiled but only changed modules were tested (2 modules)
  • Camel :: Main
  • Camel :: Util

⚙️ View full build and test results

@davsclaus davsclaus merged commit f6f300e into apache:main May 19, 2026
6 checks passed
@davsclaus davsclaus deleted the fix/camel-23479-virtual-threads-early-config branch May 19, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants